﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;

namespace PersonaLibrary.View
{
	internal sealed class ViewWrapper<TUserControl> : IView
		where TUserControl : UserControl, new()
	{
		private readonly UserControl _userControl;
		private Window _window;

		public ViewWrapper()
		{
			_userControl = new TUserControl();
		}

		public object DataContext
		{
			get { return _userControl.DataContext; }
			set { _userControl.DataContext = value; }
		}

		public event EventHandler Closed;

		public void Show()
		{
			if(_window == null)
				_window = new Window{Content = _userControl};

			_window.Show();
		}

		public bool? ShowDialog()
		{
			if (_window == null)
				_window = new Window { Content = _userControl };

			return _window.ShowDialog();
		}

		public void Close()
		{
			_window.Close();
		}

		public event RoutedEventHandler Loaded;
		public event CancelEventHandler Closing;

		public void Hide()
		{
			_window.Hide();
		}
	}
}
